attribute vec3 a_posL;
attribute vec2 a_uv;

uniform mat4 u_mvp;
uniform sampler2D  u_heightmap;

varying vec2 v_uv;
varying	vec4 v_color;
varying float v_eyeDist;

void main()
{
	vec4 u_eyePos = vec4(0.0,0.0,0.0,1.0);

	vec4 posL = vec4(a_posL, 1.0);
	gl_Position = u_mvp * posL;
	
	// Transform vertex to view-space
    vec4 vViewPos = u_mvp * posL;
	posL = texture2D(u_heightmap, a_uv);
	gl_Position.y += posL.r*5.0 + posL.g*10.0 + posL.b*5.0;
    // Compute the distance to eye
    v_eyeDist = sqrt((vViewPos.x - u_eyePos.x)*(vViewPos.x - u_eyePos.x) +(vViewPos.y - u_eyePos.y) *(vViewPos.y - u_eyePos.y) +(vViewPos.z - u_eyePos.z) *(vViewPos.z - u_eyePos.z) );
	v_uv = a_uv;
	v_color = posL;
}
